int cmp(int* a, int* b) {
    return *a - *b;
}

void merge(int* nums1, int nums1Size, int m, int* nums2, int nums2Size, int n) {
  int p1=m-1;
  int p2=n-1;
  int tail=m+n-1;
  int cur=0;
  while(p1>=0||p2>=0)
  {
      if(p1==-1)
      {
          cur=nums2[p2--];
      }
      else if(p2==-1)
      {
          cur=nums1[p1--];
      }
      else if(nums1[p1]<nums2[p2])
      {
          cur=nums2[p2--];
      }
      else
      {
          cur=nums1[p1--];
      }
      nums1[tail--]=cur;
  }
}

void merge(int* nums1, int nums1Size, int m, int* nums2, int nums2Size, int n) {
    int sorted[m + n];
    int p1, p2 = 0;
    int cur = 0;
    while (p1 < m || p2 < n)
    {
        if (p1 == m)
        {
            cur = nums2[p2++];
        }
        else if (p2 == n)
        {
            cur = nums1[p1++];
        }
        else if (nums1[p1] < nums2[p2])
        {
            cur = nums1[p1++];
        }
        else
        {
            cur = nums2[p2++];
        }
        sorted[p1 + p2 - 1] = cur;
    }
    for (int i = 0; i < m + n; i++)
    {
        nums1[i] = sorted[i];
    }
}

int cmp(int* a, int* b) {
    return *a - *b;
}

void merge(int* nums1, int nums1Size, int m, int* nums2, int nums2Size, int n) {
    int i = 0;
    int k = m;
    while (i < n)
    {
        nums1[k++] = nums2[i++];
    }
    qsort(nums1, m + n, sizeof(int), cmp);
}